import { ConfigService } from "../../ConfigModule/config.service";
import { createConnection } from "typeorm";

const fs = require('path');
export const databaseProviders = [{
    provide:'typeormToken',
    useFactory: async (config:ConfigService)=>await createConnection({
        type:<any>config.databaseType,
        host:config.databaseHost,
        port:config.databasePort,
        username:config.databaseUser,
        password:config.databasePassword,
        timezone:'+08:00',
        charset:'utf8mb4',
        synchronize:config.databaseSynchronize,
        entities:[fs.resolve(__dirname,'../entities/*.entity{.js,.ts}')]
    }),
    inject:[ConfigService]
}]
